#include ("/_includes/_layout.html")
#@layout("订单详情", "wxmall,点步科技", "Wxmall社区","wxmall")
#define content()
    <div class="weui-form-preview">
      <div class="weui-form-preview__hd">
      	#if (orderDetail.orderType == 2)
      	<div class="weui-form-preview__item">
          <label class="weui-form-preview__label">拼团订单</label>
          <em class="weui-form-preview__value">#(orderDetail.groupStatus??)</em>
        </div>
      	#end
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">订单状态</label>
          <em class="weui-form-preview__value">#(orderDetail.orderStatus??)</em>
        </div>
      </div>
      #if (orderDetail.orderType == 7)
   	  <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">门店名称</label>
          <span class="weui-form-preview__value">#(orderDetail.shopName??)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">收货地址</label>
          <span class="weui-form-preview__value">#(orderDetail.shopAddr??)</span>
        </div>
      </div>
      #else
      <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">收货人</label>
          <span class="weui-form-preview__value">#(orderDetail.receiverName??)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">电话/手机</label>
          <span class="weui-form-preview__value">#(orderDetail.receiverPhone??)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">收货地址</label>
          <span class="weui-form-preview__value">
          #(orderDetail.receiverProvince??)#(orderDetail.receiverCity??)#(orderDetail.receiverCountry??)
          <br>#(orderDetail.receiverAddr??)</span>
        </div>
      </div>
      #end

      
      <!-- 商品项 -->
       <div class="weui-form-preview__bd">
       <div class="weui-panel weui-panel_access">
		  <!-- <div class="weui-panel__hd">订单项</div> -->
		  <div class="weui-panel__bd">
		  	#for (orderItem : orderDetail.orderItems)
		    <a href="#(webctx)/product/detail/?id=#(orderItem.productId)" class="weui-media-box weui-media-box_appmsg">
		      <div class="weui-media-box__hd">
		        <img class="weui-media-box__thumb" src="#(orderItem.productImg)">
		      </div>
		      <div class="weui-media-box__bd">
		        <h4 class="weui-media-box__title" style="font-size: 14px;">#(orderItem.productName)</h4>
		        <p class="weui-media-box__desc">#(orderItem.quantity)件</p>
		        <p class="weui-media-box__desc"><span class="price">#(orderItem.totalPrice)元</span></p>
		      </div>
		    </a>
		    #end
		  </div>
		</div>
       </div>
      
      <div class="weui-form-preview__bd">
        <!-- <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">配送方式</label>
          <span class="weui-form-preview__value">免运费（快递发货）</span>
        </div> -->
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">买家留言</label>
          <span class="weui-form-preview__value">#(orderDetail.buyerMemo)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">合计</label>
          <span class="weui-form-preview__value">￥#(orderDetail.totalPrice)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">运费</label>
          <span class="weui-form-preview__value">￥#(orderDetail.postFee)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">应付金额</label>
          <span class="weui-form-preview__value">￥#(orderDetail.payFee)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">订单编号</label>
          <span class="weui-form-preview__value">#(orderDetail.orderSn)</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">创建日期</label>
          <span class="weui-form-preview__value">#(orderDetail.orderCreated)</span>
        </div>
      </div>
      
      #if (orderDetail.orderStatus == "待支付")
      <div class="weui-form-preview__ft">
        <a id="zhifu" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:void(0)">立即支付</a>
        <a id="quxiao" class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:void(0)">取消订单</a>
      </div>
      #end
      
      #if(orderDetail.orderStatus == "已支付")
      <div class="weui-form-preview__ft">
      	<a id="shipping" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:void(0)">提醒发货</a>
        <a id="applyRefund" class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:void(0)">申请退款</a>
      </div>
      #end
      
      #if(orderDetail.orderStatus == "待退款")
      <div class="weui-form-preview__ft">
      	<a id="shipping" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:void(0)">提醒退款</a>
        <a id="cancelRefund" class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:void(0)">撤销退款申请</a>
      </div>
      #end
      
      <!--  #if(orderDetail.orderStatus == "已发货")
      <div class="weui-form-preview__ft">
      	<a id="" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:void(0)"></a>
        <a id="applyRefund" class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:void(0)">申请退款</a>
      </div>
      #end -->
      
      
    </div>
#end
#include ("/_includes/menus.html")
<script type="text/javascript">
$("#quxiao").click(function(){
	$.confirm("确认取消吗？", "确认", function() {
		$.showLoading("正在提交...");
		$.post("#(webctx)/order/cancel", {orderId:#(orderDetail.orderId)}, function(resp){
			$.hideLoading();
			if(resp.code != 200){
				$.alert(resp.msg==null ? "系统错误" : resp.msg);
				return;
			}
			showMsg("订单已取消", function(){
	    		location.href = "#(webctx)/order";		            		
	    	});
		});
	});
});

//
$("#shipping").click(function(){
		$.alert("提醒成功");
})
//申请退款
$("#applyRefund").click(function(){
	$.confirm("确认申请退款吗？", "确认", function() {
		$.showLoading("正在提交...");
		$.post("#(webctx)/order/applyRefund", {orderId:#(orderDetail.orderId)}, function(resp){
			$.hideLoading();
			if(resp.code != 200){
				$.alert(resp.msg==null ? "系统错误" : resp.msg);
				return;
			}
			showMsg("订单已申请退款", function(){
	    		location.href = "#(webctx)/order";		            		
	    	});
		});
	});
})
//撤销退款申请
$("#cancelRefund").click(function(){
	$.confirm("确认撤销退款申请吗？", "确认", function() {
		$.showLoading("正在提交...");
		$.post("#(webctx)/order/cancelRefund", {orderId:#(orderDetail.orderId)}, function(resp){
			$.hideLoading();
			if(resp.code != 200){
				$.alert(resp.msg==null ? "系统错误" : resp.msg);
				return;
			}
			showMsg("订单已撤销", function(){
	    		location.href = "#(webctx)/order";		            		
	    	});
		});
	});
})

//订单支付
$("#zhifu").click(function(){
	//发起支付
	$.showLoading("正在连接微信支付...");
	$.post("#(webctx)/pay", {orderId:#(orderDetail.orderId)}, function(data){
		$.hideLoading();
  		var resp = data;
		if(resp.code != 200){
			$.alert(resp.msg==null ? "系统错误" : resp.msg);
			return;
		}
		var json = resp.data;
		if(json.returnMsg=='OK'){
			WeixinJSBridge.invoke(
		       'getBrandWCPayRequest', {
		            "appId":json.appId,     		//公众号名称，由商户传入     
		            "nonceStr":json.nonceStr, 		//随机串     
		            "package":json.packageValue,
		            "paySign":json.paySign, 		//微信签名 
		            "signType":"MD5",         		//微信签名方式：     
		            "timeStamp":json.timeStamp      //时间戳，自1970年以来的秒数     
		     	},
		       	function(res){     
		            if(res.err_msg == "get_brand_wcpay_request:ok" ) {
		            	//使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
		            	//location.href="#(webctx)/pay/success";
		            	showMsg("支付成功", function(){
		            		location.href = "#(webctx)/user"		            		
		            	});
		            }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
		            }else {
		            	$.alert("支付失败" + res.err_msg);
		            }     
		       	}
		    );
		}
	});
});
</script>


